package com.bright.tactiviti.activiti.controller;

import com.bright.tactiviti.activiti.entity.ActCategory;
import com.bright.tactiviti.activiti.service.ActCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api("流程分类管理接口")
@RequestMapping("/tactiviti/actCategory")
public class ActCategoryController {

    @Autowired
    private ActCategoryService actCategoryService;
    @PostMapping("/add")
    @ApiOperation("添加")
    public void add(@ModelAttribute ActCategory actCategory) throws Exception {
        actCategoryService.saveEntity(actCategory);
        if(!actCategory.getParentId().equals(0)){
            ActCategory parent = actCategoryService.get(actCategory.getParentId());
            if(parent.getIsParent()==null||!parent.getIsParent()){
                parent.setIsParent(true);
                actCategoryService.editEntity(parent);
            }
        }
    }
}
